<template>
  <div>
    <div class="tabs">
      <span 
        v-for="(item,index) in tabsArr" 
        v-bind:class="tabIdx==index?'active':''" 
        v-on:click="handleTab(index)"
      >{{item}}</span>
    </div>
    <div class="cont" v-if="tabIdx==0">吃多少？</div>
    <div class="cont" v-if="tabIdx==1">睡多久？</div>
    <div class="cont" v-if="tabIdx==2">怎么打？</div>
    <div class="cont" v-if="tabIdx==3">打多久？</div>
  </div>
</template>

<script>
  export default {
    data(){
      return {
        tabIdx:0,  //1.设计数据 
        tabsArr:['吃饭','睡觉','打豆豆','打篮球']
      }
    },
    methods:{
      handleTab(n){
        this.tabIdx = n //3. 修改数据
      }
    }
  }
</script>

<style lang="scss" scoped>
.tabs span{
  padding: 10px;
  background-color: #d8d8d8;
  margin: 5px;
}
.tabs .active{
  background-color: orange;
  color: #fff;
}
.cont{
  height: 300px;
  width: 300px;
  border: 2px solid #333;
  margin: 10px;
}
</style>